package com.Web.guardians;

import com.DAO.Impl.guardiansDAOImpl;
import com.google.gson.Gson;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 20x
 * @date 2024 - 12 -11
 **/
@WebServlet("/SendMessage")
public class SendMessage extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Gson gson = new Gson();

        String recipientId = req.getParameter("recipientId");
        String recipientName = req.getParameter("recipientName");
        String title = req.getParameter("title");
        String content = req.getParameter("content");
        String image = req.getParameter("image");
        String newImage = "../img/bg/activity/"+image;
        System.out.println(recipientId+recipientName+title+content+newImage);
        int count = new guardiansDAOImpl().SendMessage(recipientId,recipientName,title,content,newImage);
        if (count>0){
            out.print(gson.toJson("发送成功"));
        }
    }
}
